<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('账户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>账本名称：</label>
                            <input type="text" name="accountName"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="account:account:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="account:account:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="account:account:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="account:account:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var detailFlag = [[${@permission.hasPermi('account:account:detail')}]];
    var analysisFlag = [[${@permission.hasPermi('account:account:analysis')}]];
    var editFlag = [[${@permission.hasPermi('account:account:edit')}]];
    var removeFlag = [[${@permission.hasPermi('account:account:remove')}]];
    var visibleDatas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "account/account";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "记账账户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false,  // 隐藏某列（列选项可见）
                    ignore: true,    // 列选项不可见
                },
                // {
                //     field: 'cover',
                //     title: '账户封面/图片'
                // },
                {
                    field: 'accountName',
                    title: '账本名称',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'accountIntroduce',
                    title: '账本介绍',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 23, "open");
                    }
                },
                {
                    field: 'visible',
                    title: '账本状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabels(visibleDatas, value);
                    }
                },
                {
                    field: 'orderNum',
                    title: '显示顺序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + analysisFlag + '" href="javascript:void(0)" onclick="analysis(\'' + row.id + '\')"><i class="fa fa-bar-chart-o"></i>分析</a> ');
                        var more = [];
                        if (row.administrators === '1' ) {
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authUser(" + row.id + ")'><i class='fa fa-user'></i> 分配用户</a>");
                        }else{
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authUser(" + row.id + ")'><i class='fa fa-user'></i>查看用户</a>");
                        }
                        more.push("<a class='btn btn-default btn-xs " + removeFlag + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='$.operate.edit(" + row.id + ")'><i class='fa fa-edit'></i>编辑</a>");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*账户列表-详细*/
    function detail(id) {
        var url = prefix + '/detail/' + id;
        $.modal.openTab("账目明细", url);
    }

    /*账户列表-分析*/
    function analysis(id) {
        var url = prefix+'/accountAnalysisPage/' + id;
        $.modal.openTab("账目明细", url);
    }

    /* 账户管理-分配用户 */
    function authUser(id) {
        var url = prefix + '/authUser/' + id;
        $.modal.openTab("分配用户", url);
    }
</script>
</body>
</html>
